package com.glsc.ngateway.common.base.enums;

import com.glsc.ngateway.common.api.common.utils.encrypt.AESEncrypt;
import com.glsc.ngateway.common.api.common.utils.encrypt.RSAEncrypt;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;

import java.util.function.Function;

@AllArgsConstructor
@NoArgsConstructor
public enum EncryptTypeEnum {
    AES(AESEncrypt::encrypt, AESEncrypt::decrypt),
    RSA(str -> {
        try {
            return RSAEncrypt.encrypt(str);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }, str -> {
        try {
            return RSAEncrypt.decrypt(str);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }),
    ;
    /**
     * 加密
     */
    private Function<String, String> encrypt;
    /**
     * 解密
     */
    private Function<String, String> decrypt;

    public String encrypt(String s) {
        return this.encrypt.apply(s);
    }

    public String decrypt(String s){
        return this.decrypt.apply(s);
    }
}
